<?php
require 'header.php';//引入头文件
include("connect.php");  //引用数据库链接文件
?>
  <div class="container">
	
	  <div class="card border border-info" >
	    <img src="./img/timg.jpg" class="card-img-top">
	    <div class="card-body">
		<?php
	  	  $sql="select * from demand  order by id DESC"; 
	  			$result=mysqli_query($conn,$sql);
	  			while($data=mysqli_fetch_array($result))
	  {
	  ?>
	      <div class="card" style="margin-top: 10px;">
	        <div class="card-header">
	         《<?php echo $data['title']?>》
	        </div>
	        <div class="card-body"> 
			<h6 class="card-subtitle mb-2 text-muted"></h6>
	      			<?php if($data['need']=="一般"){
	      				?>
	      				 <h5 class="card-title">需求程度：<span class="badge badge-pill badge-secondary"><?php echo $data['need']?></span></h5>
	      			<?php
	      			}else if($data['need']=="需要"){?>
	      				<h5 class="card-title">需求程度：<span class="badge badge-pill badge-warning"><?php echo $data['need']?></span></h5>
	      			<?php
	      			}else if($data['need']=="急需"){?>
	      				<h5 class="card-title">需求程度：<span class="badge badge-pill badge-danger"><?php echo $data['need']?></span></h5>
	      			<?php
	      			}?>
	          <p class="card-text">	<?php echo $data['content']?></p>
	        </div>
	      		<div class="card-footer text-muted">
	      		发布人：<?php echo $data['username']?> 发布时间：<?php echo $data['time']?>
	      		  </div>
	      </div>
		  <script type="text/javascript">
	</script>
	      <?php
	      }
	      	?>
	    </div>
	  </div>
	<?php 
	if($_SESSION['username']==""){
		?>
		<div class="card text-center" style="margin: 30px;">
		<div class="card-header bg-danger text-white">
		  提示
		</div>
		<div class="card-body">
		  <h5 class="card-title">还未登录</h5>
		  <p class="card-text">登录后才可发布书籍请求</p>
		  <a href="javascript:;" data-toggle="modal" data-target="#exampleModal" class="btn btn-primary">点击登录</a>
		</div>
	  </div>
	  <?php
	}else{
	?>
	  <div class="card border border-primary" style="margin-top: 20px; ">
	    <div class="card-header">
	      提需求
	    </div>
	    <div class="card-body">
	      <h5 class="card-title">填写您需要的:	</h5>
	      <form  method="post"   name="spinfo" action="assisting.php?action=assist&id=<?php echo $id?>">
	        <div class="form-group">
	          <label for="exampleFormControlInput1">书籍名</label>
	          <input type="text" required="required" class="form-control" name="title" id="exampleFormControlInput1">
	        </div>
	        <div class="form-group">
	          <label for="exampleFormControlSelect1">需求程度</label>
	          <select class="form-control" id="exampleFormControlSelect1" name="need">
	            <option>一般</option>
	            <option>需要</option>
	            <option>急需</option>
	          </select>
	        </div>
	        <div class="form-group">
	          <label for="exampleFormControlTextarea1">书籍大概内容</label>
	          <textarea name="content" required="required" placeholder="请输入您想获得书籍的信息" class="form-control" id="exampleFormControlTextarea1"></textarea>
	        </div>
	      	<div class="form-group">
	      		 <button type="submit" class="btn btn-primary">发布</button>
	      	</div>
	      </form>  	
	    </div>
		</div>
  <?php 
	}
  ?>
		</div>
 
